class Solution:
    def decodeString(self,s):
        stack,res,multi=[],'',0
        for c in s:
            if c=='[':
                stack.append([multi,res])
                res,multi='',0
            elif c==']':
                cur_multi,last_res=stack.pop()
                res = last_res + cur_multi * res
                # res=last_res+res*multi    细节
            # elif '0'<=c<='9':
            #     multi=multi*10+int(c)
            # else:
            #     res+=c
        # stack, res, multi = [], "", 0
        # for c in s:
        #     if c == '[':
        #         stack.append([multi, res])
        #         res, multi = "", 0
        #     elif c == ']':
        #         cur_multi, last_res = stack.pop()
        #         res = last_res + cur_multi * res
            elif '0' <= c <= '9':
                multi = multi * 10 + int(c)
            else:
                res += c
                # res += c
        return res

class Solution_:
    def decodeString(self,s):
        def dfs(s,i):
            res,multi='',0
            while i<len(s):
                if '0'<=s[i]<='9':
                    multi=multi*10+int(s[i])
                elif s[i]=='[':
                    i,tmp=dfs(s,i+1)
                    res+=multi*tmp
                    multi=0
                elif s[i]==']':
                    return i,res
                else:res+=s[i]
                i+=1
            return res
        return dfs(s, 0)



sol=Solution_()
print(sol.decodeString('2[ee]'))